using: it is a keyword to import the namespaces. About these namespaces we will discuss as a separate chapter.

Program on Using Keyword

using System;
class sample
{
static void Main()
{
Console.WriteLine("Welcome to C# World......with Using ");
}
}

Program To Find the sum of 2nos
using System;
class sample
{
public static void Main(string []args)
{
int a=10,b=20,c;
c=a+b;
Console.WriteLine("Sum"+c);
Console.WriteLine("Sum {0}+{1}={2}",a,b,c);
}
}

 

 

Program to read the string from the input device
class sample
{
public static void Main(string []args)
{
string k;
System.Console.WriteLine("Enter Name");
k=System.Console.ReadLine();
System.Console.WriteLine("Given Name is "+k);
// Alternativly we can write outputstatement as bellow
System.Console.WriteLine("Given Name {0}",k);
}
}

 

Program to read the characters using Read()
using System;
class sample
{
public static void Main(string []args)
{
int a,b;
Console.WriteLine("Enter a Character");
a=Console.Read();
b=Console.Read();

Console.WriteLine(a+" "+b);               
Console.WriteLine("{0}  {1}",a,b);
Console.ReadKey();
}
}

Console.ReadKey () It is used to pause the execution.

System.Convert: this class is used to convert the data from string to other types it has several static methods.
Methods: ToInt16(),ToInt32(),ToInt64(),ToChar(),ToBoolean(),ToByte(),ToDouble()…etc

Program to find the sum of 2 nos

class sample
{
static void Main(string[] args)
{
int a, b, c;
Console.WriteLine("Enter 2nos");
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
c = a + b;
Console.WriteLine("Sum of 2nos" + c);

        }
}
note: write some programs for practice purpose

Program to find the Big no out of 3 nos

class sample
{
static void Main(string[] args)
{
int a, b, c;
Console.WriteLine("Enter 3 nos");
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
c = Convert.ToInt32(Console.ReadLine());
if (a > b && a > c)
{
Console.WriteLine("Bigno" + a);
}
else if (b > c)
{
Console.WriteLine("Bigno" + b);
}
else
{
Console.WriteLine("Bigno" + c);
}

        }
}

Note: write some programs on if for practice
Program on While
class sample
{
static void Main(string[] args)
{
int a, b=1, c = 1;
Console.WriteLine("Etner no");
a = Convert.ToInt32(Console.ReadLine());
while (b <= a)
{
c *= b;
b++;
}
Console.WriteLine("Factorial Value" + c);

        }
}
Find the Armstrong or not using Do..While
class sample
{
static void Main(string[] args)
{
int a, b, c = 0, d;
Console.WriteLine("Etner no");
a = Convert.ToInt32(Console.ReadLine());
d = a;
do
{
b = a % 10;
a = a / 10;
c = c + b * b * b;
}
while (a > 0);
if (c == d)
Console.WriteLine("Armstriong");
else
Console.WriteLine("Not armstrong");
}

}

Program to print the Prime numbers in the given range using FOR
class sample
{
static void Main(string[] args)
{
int a, b, c;
Console.WriteLine("Enter Max Range");
a = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= a; i++)
{
c = 0;
for (int j = 1; j <= i; j++)
{
if (i % j == 0)
c++;
}
if (c <= 2)
Console.WriteLine("Prime" + i);
}
}
}

Note: do some more programs on loops for practice purpose

 

Program on Switch case
class sample
{
static void Main(string[] args)
{
int a, b, ch;
Console.WriteLine("1.add\n2.Sub\n3.Sub\n4.Mul\n5.Exit\nEnter choice");
ch =Convert.ToInt32 ( Console.ReadLine());
if (ch>4)
return;
Console.WriteLine("Enter 2nos");
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
switch (ch)
{
case 1:
Console.WriteLine("Sum of 2nos" + (a + b));
break;
case 2:
Console.WriteLine("Sub of 2nos" + (a - b));
break;
case 3:
Console.WriteLine("Mul of 2nos" + (a * b));
break;
case 4:
Console.WriteLine("Div of 2nos" + (a / b));
break; // we can write goto default
default:
Console.WriteLine("Illegal option");
break;

            }

        }
}